<%-- 
    Document   : index
    Created on : 2012-maj-03, 16:43:36
    Author     : Karl Viring
--%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<LINK href="stylesheet.css" rel="stylesheet" type="text/css">
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>WebBucks Online Coffee Company!</title>
        <style>.error { color: red; } .success { color: green; }</style>
    </head>
    <body>
        <div id="content">
            <div id="loginpane">
                <c:choose>
                    <c:when test="${! empty validUser && validUser == true}">
                        Current User: ${currentUser}
                        <a href="/webbucks-war/IndexServlet?action=logout">Log out</a>
                        <a href="updateCustomer.jsp">Update profile</a>
                    </c:when>
                    <c:otherwise>
                        <a href="login.jsp">Login or register</a>
                    </c:otherwise>
                </c:choose>
                <a href="/webbucks-war/Manager">Manage shop</a>
            </div>
            
            <div id="header">
                <h1>WebBucks!</h1>
            </div>
            
            <span id="products">
                
                <h2 class="products">Products</h2>
                <ul>
                    <c:forEach items="${products}" var="product">
                        <li>
                            ${product.name} (<c:forEach items="${product.ingredients}" var="ingredient" varStatus="status">
                                ${ingredient.name}
                                <c:if test="${ ! status.last}">
                                    ,
                                </c:if>
                            </c:forEach>), 
                            ${product.price}:-
                            <a href="/webbucks-war/IndexServlet?action=add&id=${product.name}">Add to cart</a>
                        </li>
                    </c:forEach>  
                </ul>
                
            </span>
            
            <span id="shoppingcart">
                <h2 class="products">My shopping cart</h2>
                <table>
                    <tr>    
                        <td class="cartheader">Product</td>
                        <td class="cartheader">Quantity</td>
                        <td class="cartheader">Price</td>
                        <td class="cartheader">+/-</td>
                    </tr>
                    <c:forEach items="${cart}" var="cart">
                        <tr>
                            <td>${cart.key}</td>
                            <td>${cart.value.n} pcs</td>
                            <td>${cart.value.p.price * cart.value.n}</td>
                            <td><a href="/webbucks-war/IndexServlet?action=add&id=${cart.key}"><img src="add.png"></img></a>/<a href="/webbucks-war/IndexServlet?action=remove&id=${cart.key}"><img src="remove.png"></img></a></td>
                        </tr>
                    </c:forEach>  
                    <tr>
                        <td class="totalprice">Total price:</td>
                        <td class="totalprice"></td>
                        <td class="totalprice"><c:out value="${total_price}"/> :-</td>
                        <td class="totalprice"></td>                        
                    </tr>        
                </table>
                <a href="/webbucks-war/IndexServlet?action=checkout">Proceed to checkout<img src="checkout.png"></img></a>
            </span>
        </div>           
    </body>
</html>